package com.java.tutorials.jdk7.fileattribute;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
import java.util.Calendar;
/**
 * Created by xuzhike on 2016/1/24.
 * http://www.java2s.com/Code/Java/JDK-7/UseFileTime.htm
 */
public class UseFileTimeTest {
    public static void main(String[] args) throws Exception{
        Path path = Paths.get("e:/yjbWechat.txt");
        BasicFileAttributeView view = Files.getFileAttributeView(path,
                BasicFileAttributeView.class);

        BasicFileAttributes attributes = view.readAttributes();
        FileTime lastModifedTime = attributes.lastModifiedTime();
        FileTime createTime = attributes.creationTime();

        long currentTime = Calendar.getInstance().getTimeInMillis();
        FileTime lastAccessTime = FileTime.fromMillis(currentTime);

        view.setTimes(lastModifedTime, lastAccessTime, createTime);
        System.out.println(attributes.lastAccessTime());
    }
}
